//
//  LZCouponManagerGroupDetailViewController.m
//  laziz_Merchant
//
//  Created by xbnzd on 16/12/20.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCouponManagerGroupDetailViewController.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "LZGroupDetailTopCell.h"
#import "LZFightGroupDetailOrderRulesCell.h"
#import "LZFightGroupDetailMealsTimeCell.h"
#import "LZFightGroupDetailRulesOfUseCell.h"
#import "LZCouponListModel.h"
#import "LZDateFormatterManager.h"

static NSString *kTitleCell = @"titlecell";
static NSString *kOrderRulesCell = @"orderrulescell";
static NSString *kRulesofUseCell = @"termsofuse";
static NSString *kMealTimeCell = @"mealcell";

@interface LZCouponManagerGroupDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation LZCouponManagerGroupDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.umLogPageViewName = @"优惠管理-团购详情页面";
    [self configureUI];
}

#pragma mark -
#pragma mark configure ui
- (void)configureUI
{
    self.title = LZLocalizedString(@"group_order_details", nil);
    [self.tableView registerNib:[UINib nibWithNibName:@"LZGroupDetailTopCell" bundle:nil] forCellReuseIdentifier:kTitleCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailOrderRulesCell" bundle:nil] forCellReuseIdentifier:kOrderRulesCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailMealsTimeCell" bundle:nil] forCellReuseIdentifier:kMealTimeCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailRulesOfUseCell" bundle:nil] forCellReuseIdentifier:kRulesofUseCell];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}

#pragma mark -
#pragma mark tableview  delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WS(wSelf);
    switch (indexPath.row) {
        case 0:
            return [tableView fd_heightForCellWithIdentifier:kTitleCell configuration:^(id cell) {
                LZGroupDetailTopCell *cellTemp = (LZGroupDetailTopCell *)cell;
                [cellTemp loadContentWithData:wSelf.dataModel];
            }];
            break;
        case 1:
            return [tableView fd_heightForCellWithIdentifier:kOrderRulesCell configuration:^(id cell) {
                LZFightGroupDetailOrderRulesCell *cellTemp = (LZFightGroupDetailOrderRulesCell *)cell;
 
                [cellTemp loadMembersNum:[NSString stringWithFormat:@"%d",wSelf.dataModel.grouponCount] FinishedTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.dataModel.grouponEndTime]];
                
            }];
            break;
        case 2:
            return [tableView fd_heightForCellWithIdentifier:kRulesofUseCell configuration:^(id cell) {
                LZFightGroupDetailRulesOfUseCell *cellTemp = (LZFightGroupDetailRulesOfUseCell *)cell;
                [cellTemp loatGrouponName:@"" RulesContent:wSelf.dataModel.grouponRemindRule ExpirationTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.grouponDeadline]];
            }];
            break;
        case 3:
            return [tableView fd_heightForCellWithIdentifier:kMealTimeCell configuration:^(id cell) {
                LZFightGroupDetailMealsTimeCell *cellTemp = (LZFightGroupDetailMealsTimeCell *)cell;
                NSString *everyDayValid = [wSelf.dataModel getGroupEverydayValid];
                [cellTemp loadValidExcept:wSelf.dataModel.grouponExceptTime EverydayValid:everyDayValid otherContent:wSelf.dataModel.grouponRemindAppoint];
            }];
            break;
        default:
            break;
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:{
            LZGroupDetailTopCell *cell = [tableView dequeueReusableCellWithIdentifier:kTitleCell];
            [cell loadContentWithData:self.dataModel];
            
            return cell;
        }
            
            break;
        case 1:{
            LZFightGroupDetailOrderRulesCell *cell = [tableView dequeueReusableCellWithIdentifier:kOrderRulesCell];
            [cell loadMembersNum:[NSString stringWithFormat:@"%d",self.dataModel.grouponCount] FinishedTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.grouponEndTime]];
            return cell;
        }
            
            break;
        case 2:{
            LZFightGroupDetailRulesOfUseCell *cell = [tableView dequeueReusableCellWithIdentifier:kRulesofUseCell];
            [cell loatGrouponName:@"" RulesContent:self.dataModel.grouponRemindRule ExpirationTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.dataModel.grouponDeadline]];

            return cell;
        }
            
            break;
        case 3:{
            LZFightGroupDetailMealsTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:kMealTimeCell];
            NSString *everyDayValid = [self.dataModel getGroupEverydayValid];
            [cell loadValidExcept:self.dataModel.grouponExceptTime EverydayValid:everyDayValid otherContent:self.dataModel.grouponRemindAppoint];
            return cell;
        }
            
            break;
            
        default:
            break;
    }
    
    return nil;
}


@end
